<?php

session_start();
include ("inc/validate_user.inc");

require_once('inc/db_access.inc');
require_once('inc/utils.inc');
require_once('inc/notes.inc');
require_once('inc/wall.inc');

$uid =  $_SESSION['uid'];

$dbc = new DBConnection();
$dbc->getNewConnection();

$wn = $_REQUEST['wall_name'];
if($wn){
	add_wall($dbc, $uid, $wn);
}

$wallList = get_wall_list($dbc, $uid);
?>
<html>
<head>
<!-- Dependencies --> 
<!-- Sam Skin CSS for TabView --> 
<link rel="stylesheet" type="text/css" href="yui/tabview/assets/skins/sam/tabview.css"> 
 
<!-- JavaScript Dependencies for Tabview: --> 
<script type="text/javascript" src="yui/yahoo-dom-event/yahoo-dom-event.js"></script> 
<script type="text/javascript" src="yui/element/element-min.js"></script> 
 
<!-- OPTIONAL: Connection (required for dynamic loading of data) --> 
<script type="text/javascript" src="yui/connection/connection-min.js"></script> 
 
<!-- Source file for TabView --> 
<script type="text/javascript" src="yui/tabview/tabview-min.js"></script>

<!--CSS file (default YUI Sam Skin) -->
<link type="text/css" rel="stylesheet" href="yui/autocomplete/assets/skins/sam/autocomplete.css">

<!-- Dependencies -->
<script type="text/javascript" src="yui/datasource/datasource-min.js"></script>

<!-- OPTIONAL: Get (required only if using ScriptNodeDataSource) -->
<script type="text/javascript" src="yui/get/get-min.js"></script>


<!-- OPTIONAL: Animation (required only if enabling animation) -->
<script type="text/javascript" src="yui/animation/animation-min.js"></script>

<!-- OPTIONAL: JSON (enables JSON validation) -->
<script type="text/javascript" src="yui/json/json-min.js"></script>

<!-- Source file -->
<script type="text/javascript" src="yui/autocomplete/autocomplete-min.js"></script>

<!-- Drag and Drop source file -->  
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/dragdrop/dragdrop-min.js" ></script> 

<!-- Dispatcher for JS injection-->
<script type="text/javascript" src="yui/dispatcher/dispatcher-min.js"></script>
<script type="text/javascript" src="yui/dispatcher/dispatcher.js"></script>
<script type="text/javascript" src="javascript/notes_operation.js"></script>
<script type="text/javascript" >
function on_load(){
	if(document.getElementById('autocomplete')){
		var oDS = new YAHOO.util.XHRDataSource("tags.php");
		oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
		// Define the schema of the delimited results
		oDS.responseSchema = {
        		recordDelim: "\n",
        		fieldDelim: "\t"
    		};
    		// Enable caching
    		oDS.maxCacheEntries = 5;

    		// Instantiate the AutoComplete
    		var oAC = new YAHOO.widget.AutoComplete("note_tags", "autocomplete", oDS);

	}
	get_all_notes();
}
</script>
</head>
<body class='yui-skin-sam' onload="on_load()">
<h3>Add Wall</h3>
<form method='post' action="<?php echo $_SERVER['PHP_SELF'];?>">
Name:<input name='wall_name' >
<input type='submit' >
</form>
<div id='container'>
	<ul class='yui-nav'>
		<li class='selected'><a href="#tab1"><em>Add Notes</em></a></li>
		<li ><a href="#tab2"><em>Scratch Pad</em></a></li>
	<?php
	foreach($wallList as $wall){
		echo "<li ><a href='#wall_$wall[0]'><em>$wall[1]</em></a></li>\n";
	}
	?>
	</ul>
	<div class="yui-content"> 
		<div id='tab1'>
		<div class='yui-skin-sam'>
			Note : <textarea name='note_txt' id='note_txt' style='width:250'></textarea> <br/>
			Tags : <input autocomplete='false' name='note_tags' id='note_tags' style='width:250' ><br/>
			<div id='autocomplete' ></div>
			<input type='button' onclick='javascript:add_notes()' value='post' >
		</div>
		<table border='1' id='notes_tbl'>
		<tr><th>Note</th><th>Tags</th></tr>
		</table>

		</div>
		<div id="tab2">
		<?php include("inc/scratch_pad.inc"); ?>
		</div>
		<?php
		foreach($wallList as $wall){
			echo "<div id='wall_$wall[0]' style='height:70%' >\n";
			echo "Loading...\n";
			echo "</div>\n";
		}
		?>
	</div>
</div>

<script>
var tabView = new YAHOO.widget.TabView('container'); 
var wallId = []; 
<?php foreach($wallList as $wall){
	echo "wallId[wallId.length] = '$wall[0]';\n";
}

?>

function tabChange(e){
	var wall_id = wallId[e.newValue-2];
	if(wall_id)
		render_wall(wall_id);
	/*
	if(wall_id && !document.getElementById(wall_id)){
		var ndiv = document.createElement('div');
		ndiv.style.width = '200px';
		ndiv.style.height = '200px';
		ndiv.style.backgroundColor = 'yellow';
		ndiv.innerHTML = 'Tnotes';
		ndiv.id = wall_id;

		var wdiv = document.getElementById('wall_'+wall_id);
		wdiv.innerHTML = '';
		wdiv.appendChild (ndiv);
		var dd = new YAHOO.util.DD(ndiv);
		dd.on('endDragEvent', function(e){
			//alert(ndiv.style.top+','+ndiv.style.left);
		}, dd, true);
	}*/
}
tabView.on('activeIndexChange', tabChange);
</script>
</body>
</html>
